<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.util.CodeTableUtil"%>
<%@page import="com.feib.soeasy.model.UploadFile"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>上傳記錄查詢</title>
	<script type="text/javascript">
	<!--	
	$(document).ready(function() {
		$("[id^='viewPaymentImg-']").click(function() {
			var uploadFilePk = this.id.substring(15);
			doQueryPaymentsAction(uploadFilePk);
		});
	});
	
	function doQueryPaymentsAction(uploadFilePk)
	{
		$('#hidden\\.qryUploadFile\\.uploadFilePk').val(uploadFilePk);
		
		$("#paymentGroupDiv").fadeTo("slow", 0.1);
		
		waitingDialog({});
		
		$.ajax({url : "<c:url value='/ajax/Soez2003.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#paymentGroupDiv").html(data);
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
		});
		$("#paymentGroupDiv").fadeTo("slow", 1);
	}
	
	//-->
	</script>
</head>
<body>
<stripes:form id="queryUploadFileFrom" beanclass="com.feib.soeasy.action.Soez2003ActionBean" 
			method="post" onsubmit="javascript: return false;">
<div id="queryHiddenFormDiv">
<c:choose>
	<c:when test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">
		<c:set var="lastPageNumber" value="${actionBean.queryResult.totalPageCount}"/>
		<c:set var="currentPageNumber" value="${actionBean.queryResult.pageNumber}"/>
		<c:set var="prePageNumber" value="${actionBean.queryResult.pageNumber - 1}"/>
		<c:set var="nextPageNumber" value="${actionBean.queryResult.pageNumber + 1}"/>
		<table id="listTable">
			<thead>
				<tr>
					<th id="paginationBar" colspan="10">
						<input type="button" id="firstPageBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						<input type="button" id="prePageBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
						第 <input type="text" id="currentPageText" value="${currentPageNumber }" size="3" maxlength="4"> / ${lastPageNumber} 頁
						<input type="button" id="nextPageBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
						<input type="button" id="lastPageBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
					</th>
				</tr>
				<tr>
					<th>上傳日期</th>
					<th>檔案名稱</th>
					<th>上傳格式</th>
					<th>上傳人員</th>
					<th>總筆數</th>
					<th>總金額</th>
					<%if ( UserUtil.isBankGroup()){ %>
					<th>業者名稱</th>
					<%} %>
					<th>&nbsp;</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
				<tr>
					<td><fmt:formatDate value="${viewObj.uploadDate}" pattern="yyyy/MM/dd" /></td>
					<td><c:out value="${viewObj.fileName}"/></td>
					<td><c:out value="${viewObj.formatDefinition.formatName}"/></td>
					<td>
						<c:choose>
							<c:when test="${null != viewObj.uploadUser }"><c:out value="${viewObj.uploadUser.userName}"/></c:when>
							<c:otherwise>&nbsp;</c:otherwise>
						</c:choose>
					</td> 
					<td><fmt:formatNumber value="${viewObj.totalItems}" pattern="##,###" /></td>
					<td><fmt:formatNumber value="${viewObj.totalAmount}" pattern="##,###" /></td>
					<td>
						<img id="viewPaymentImg-<c:out value='${viewObj.uploadFilePk}'/>" 
						src="<c:url value='/styles/default/images/view.png'/>" 
						width="25" height="25" />
					</td>					
				</tr>
				</c:forEach>
			</tbody>
		</table>
			
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$("[id^='firstPageBtn']").click(function() {
				doQueryAction(1);
			});
			
			$("[id^='prePageBtn']").click(function() {
				doQueryAction(<c:out value='${prePageNumber}'/>);
			});
			
			$("[id^='nextPageBtn']").click(function() {
				doQueryAction(<c:out value='${nextPageNumber}'/>);
			});
			
			$("[id^='lastPageBtn']").click(function() {
				doQueryAction(<c:out value='${lastPageNumber}'/>);
			});
			
			$("[id^='currentPageText']").change(function() {
				var value = this.value;
				if (value != ''){
					value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
					var intRegex = /^\d+$/;
					if(!intRegex.test(value)) {
						alert('頁數必須是整數');
						return ;
					}
					
					value = parseInt(value, 10);
					
					if (value < 1){
						alert('頁數必須是大於1');
						return ;
					}
					else if (value > <c:out value='${lastPageNumber}'/>){
						alert('頁數必須是小於總頁數 (<c:out value='${lastPageNumber}'/>)');
						return ;
					}
					else if (value != <c:out value='${currentPageNumber}'/>){
						doQueryAction(value);
					}
					
				}
				else{
					alert('頁數不可為空白');
					return ;
				}
			});
			
			$("[id^='viewFileErrorsImg-']").click(function() {
				var filePk = this.id.substring(18);
				doQueryFileErrorReasonAction(1, filePk);
			});
			
			$("[id^='veiwFilePaymentsImg-']").click(function() {
				var filePk = this.id.substring(20);
				doQueryFilePaymentsAction(1, filePk);
			});
		});
		//-->
		</script>
	</c:when>
	<c:otherwise>
		<div id="queryNothingBlockDiv" style="display: none;">
			<table id="listTable">
				<tr>
					<th>
						查無資料
					</th>
				</tr>
			</table>
		</div>		
		<script type="text/javascript">
		<!--
		$(document).ready(function() {
			$( "#queryNothingBlockDiv" ).dialog( "destroy" );
			$( "#queryNothingBlockDiv" ).dialog({  title:'帳單上傳記錄查詢' ,width: 600, resizable: false, modal: true  });
		});
		//-->
		</script>
	</c:otherwise>
</c:choose>

</div>
</stripes:form>

	<!-- 繳費總覽查詢結果  -->
	<div id="paymentGroupDiv" style="display: none;">
	</div>
	
	<div id="queryPaymentHiddenFormDiv" style="display: none;">
		<stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez2003ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<%if ( UserUtil.isBankGroup()){ %>
			<stripes:hidden id="hidden.qryUploadFile.uploadGroup.groupNo" name="qryUploadFile.uploadGroup.groupNo"/>
			<%} %>
			<stripes:hidden id="hidden.qryUploadFile.uploadFilePk" name="qryUploadFile.uploadFilePk"/>			
			<input type="hidden" id="method" name="doAjaxQueryPayments"/>
		</stripes:form>
	</div>
	
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>
	
	
</body>
</html>